﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Elysium.Controls;
using Elysium.Demo.Configuracion.Empresa;
using SIIE_ERP.Codigo;
using Elysium.Demo.Configuracion.Empresa.FacturacionElectronica;
using SIIE_ERP.BaseDatos;
using Elysium.Demo.Configuracion.PagoLicencias;
using SIIE_ERP.BaseDatos.Configuracion;
using Elysium.Demo.Ventas;
using SIIE_ERP.Codigo.Ventas;

namespace Elysium.Demo.Configuracion
{
    /// <summary>
    /// Lógica de interacción para Menu_Configuracion.xaml
    /// </summary>
    public partial class Menu_Configuracion : UserControl
    {
        private UsuarioActivo _sesion;

        public Menu_Configuracion(ref UsuarioActivo usuario)
        {
            InitializeComponent();
            this._sesion = usuario;

            if (FuncionesClass.ConsultaFE(usuario.RFC) != 1)
            {
                ButtonEmpresa_Certificados_FE.Visibility = System.Windows.Visibility.Hidden;
             //   ButtonTimbres.Visibility = System.Windows.Visibility.Hidden;                
            }
            if (FuncionesClass.ConsultaFE(_sesion.RFC) != 1)
            {

              
                    ButtonTimbres.Visibility = System.Windows.Visibility.Hidden;
                
            }
           
        }

        private void Expander_Catalogos_Expanded(object sender, RoutedEventArgs e)
        {            
            if (Expander_Transacciones != null)
                Expander_Transacciones.IsExpanded = false;
            if (Expander_Empresa != null)
                Expander_Empresa.IsExpanded = false;
            //if (Expander_Licencias != null)
            //    Expander_Licencias.IsExpanded = false;
            if (Expander_FE != null)
                Expander_FE.IsExpanded = false;
        }

        private void Expander_Transacciones_Expanded(object sender, RoutedEventArgs e)
        {
            if (Expander_Catalogos != null)
                Expander_Catalogos.IsExpanded = false;
            if (Expander_Empresa != null)
                Expander_Empresa.IsExpanded = false;
            //if (Expander_Licencias != null)
            //    Expander_Licencias.IsExpanded = false;
            if (Expander_FE != null)
                Expander_FE.IsExpanded = false;
        }

        private void Expander_Licencias_Expanded(object sender, RoutedEventArgs e)
        {
            if (Expander_Catalogos != null)
                Expander_Catalogos.IsExpanded = false;
            if (Expander_Transacciones != null)
                Expander_Transacciones.IsExpanded = false;
            if (Expander_Empresa != null)
                Expander_Empresa.IsExpanded = false;
            if (Expander_FE != null)
                Expander_FE.IsExpanded = false;
        }

        private void Expander_Empresa_Expanded(object sender, RoutedEventArgs e)
        {
            if (Expander_Catalogos != null)
                Expander_Catalogos.IsExpanded = false;
            if (Expander_Transacciones != null)
                Expander_Transacciones.IsExpanded = false;
            //if (Expander_Licencias != null)
            //    Expander_Licencias.IsExpanded = false;

            if (Expander_FE != null)
                Expander_FE.IsExpanded = true;
        }

        private void Expander_FE_Expanded(object sender, RoutedEventArgs e)
        {
            if (Expander_Catalogos != null)
                Expander_Catalogos.IsExpanded = false;
            if (Expander_Transacciones != null)
                Expander_Transacciones.IsExpanded = false;
            //if (Expander_Licencias != null)
            //    Expander_Licencias.IsExpanded = false;
        }

        private void ButtonInformacionGeneral_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new Empresa.InformacionGeneral(ref _sesion);
        }

        private void ButtonSucursales_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new Sucursales_Consulta(ref _sesion);
        }

        private void ButtonSeries_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new Series_Consulta(ref _sesion);
        }

        private void ButtonPresupuestoVentas_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new PresupuestoVentas_Consulta(ref _sesion);
        }

        private void ButtonEmpresa_Configuracion_FE_Click(object sender, RoutedEventArgs e)
        {
            if (FuncionesClass.ConsultaFE(_sesion.RFC) == 3)
                ScrollViewConfiguracion.Content = new FE_Conf2(ref _sesion);
            else if (FuncionesClass.ConsultaFE(_sesion.RFC) == 1)
                ScrollViewConfiguracion.Content = new FE_Conf3(ref _sesion);            
            else
                ScrollViewConfiguracion.Content = new FE_Conf1(ref _sesion);            
        }

        private void ButtonUsuarios_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new Usuarios_Consulta(ref _sesion);
        }

        private void ButtonEmpresa_Certificados_FE_Click_1(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new Certificado_Consulta(ref _sesion);
        }

        private void ButtonDatosBancarios_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new DatosBancarios(ref _sesion);
        }

        private void ButtonUsuarios_3_Click(object sender, RoutedEventArgs e)
        {
            ScrollViewConfiguracion.Content = new CargaDatos_Main(ref _sesion);
        }

        private void Button_TiempoAire_Click_1(object sender, RoutedEventArgs e)
        {
            if (dbo_Trans_TiempoAire_RFC.IsTiempoAireActivo(_sesion.RFC))
            {
                if (dbo_Trans_TiempoAire_RFC.IsTiempoAireInProcess(_sesion.RFC))
                    ScrollViewConfiguracion.Content = new TiempoAire_TerminosProceso(ref _sesion);
                else
                {
                    if (WebServicesClass.CheckConnection())
                        ScrollViewConfiguracion.Content = new TiempoAire_Final(ref _sesion);
                    else
                    {
                        MessageBox.Show("Necesita Conexión a Internet para acceder a este apartado");
                        return;
                    }
                }
            }
            else
                ScrollViewConfiguracion.Content = new TiempoAire_TerminosCondiciones(ref _sesion);
        }

        private void ButtonNuevaEmpresa_Click_1(object sender, RoutedEventArgs e)
        {
            Elysium.Demo.Registro.WindowRegistroEmpresa EmpresaN = new Elysium.Demo.Registro.WindowRegistroEmpresa(ref _sesion);            
            EmpresaN.Owner = SIIE_ERP.View.NavegacionUI.GetParentWindow(this); EmpresaN.ShowDialog();
        }

        private void ButtonCompraLicencia_Click_1(object sender, RoutedEventArgs e)
        {
           ScrollViewConfiguracion.Content = new CompraLicencias(ref _sesion);
           

        }

        private void ButtonTimbres_Click_1(object sender, RoutedEventArgs e)
        {
            //ScrollViewConfiguracion.Content = new Timbres(ref _sesion);
            ScrollViewConfiguracion.Content = new Elysium.Demo.Configuracion.Timbres_Consulta(ref _sesion);

        }
    }
}
